import 'package:boss/color_constant.dart';
import 'package:boss/ui/widget/custom_divier.dart';
import 'package:boss/ui/widget/modal/modal.dart';
import 'package:hi_common/hi_common.dart';
import 'package:flutter/material.dart';

Future showTextAlert<T>(
  BuildContext context, {
  dynamic content,
  VoidCallback onConfirm,
  String confirmText = '确认',
  VoidCallback onCancel,
  String cancelText = '取消',
  bool barrierDismissible = false,
}) {
  return showModal<T>(
    context,
    builder: (context) => _Alert(
      content: content,
      confirmText: confirmText,
      cancelText: cancelText,
      onConfirm: onConfirm,
      onCancel: onCancel,
    ),
    barrierDismissible: barrierDismissible,
  );
}

class _Alert extends StatefulWidget {
  final dynamic content;
  final VoidCallback onConfirm;
  final String confirmText;
  final VoidCallback onCancel;
  final String cancelText;

  const _Alert({
    Key key,
    this.content,
    this.onConfirm,
    this.confirmText,
    this.onCancel,
    this.cancelText,
  }) : super(key: key);

  @override
  __AlertState createState() => __AlertState();
}

class __AlertState extends State<_Alert> {
  @override
  Widget build(BuildContext context) {
    return Container(
      width: 640.w,
      child: Column(
        children: <Widget>[
          Container(
            alignment: Alignment.center,
            constraints: BoxConstraints(minHeight: 250.w),
            padding: EdgeInsets.symmetric(
              horizontal: 30.w,
              vertical: 20.w,
            ),
            child: _buildContent(),
          ),
          Container(
            padding: EdgeInsets.symmetric(
              horizontal: 20.w,
            ),
            child: CustomDivider(),
          ),
        ],
      ),
    );
  }

  Widget _buildContent() {
    if (widget.content is String) {
      return Text(
        widget.content,
        style: TextStyle(
          fontSize: 32.sp,
          color: ColorConstant.ff33,
          height: 1.75,
          fontWeight: FontWeight.w300,
        ),
        textAlign: TextAlign.center,
      );
    }

    if (widget.content is Widget) {
      return widget.content;
    }

    return SizedBox();
  }
}
